<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { equipApi } from '@/api/controller'
  import { Toastloading } from '@/utils/public';
  import xmImage from '@/components/xmImage/index.vue';
  import updateForm from './updateForm.vue';
  import poolTwoList from '../poolTwoList/index.vue';
  const updateFormRef = ref(),
  poolTwoListRef = ref()
  const action = reactive({
    gameList:[] as Array<any>,
    list:[] as Array<any>
  })
  const listQuery = reactive({
    game_id:'',
  })
  const filtersType = (type:number = 0)=>{
    return ['关闭','开启'][type]
  }
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      game_id:action.gameList[0]?.game_id || '',
    })
    getList()
  }
  const handleUpdate = (row:any = {})=>{
    updateFormRef.value.openDialog(row)
  }
  const openTwoList = (row:any = {})=>{
    poolTwoListRef.value.openDialog({
      ...row,
      gameList:action.gameList
    })
  }
  const getGameIdList = async()=>{
    const res = await equipApi.gameSwitch()
    const { data=[] } = res || {}
    action.gameList = data
  }
  const getList = async()=>{
    const loading = Toastloading()
    const res = await equipApi.poolOneList(listQuery)
    loading.close()
    const { data=[] } = res || {}
    action.list = data
  }
  onMounted(() => {
    getGameIdList()
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">游戏ID：</div>
          <el-select v-model="listQuery.game_id" clearable placeholder="请选择游戏ID">
            <el-option v-for="item in action.gameList" :label="item.game_name" :value="item.game_id" />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="getList">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="game_id" label="游戏ID" />
      <el-table-column min-width="120" prop="id" label="一级礼物池ID" />
      <el-table-column min-width="120" prop="item_name" label="一级礼物池名称" />
      <el-table-column min-width="120" prop="item_img" label="一级礼物池图片">
        <template #default="scope">
          <xmImage
            :src="scope.row.item_img"
            :list="[scope.row.item_img]"
          />
        </template>
      </el-table-column>
      <el-table-column min-width="130" prop="item_level" label="一级礼物池稀有度" />
      <el-table-column min-width="120" prop="sort" label="排序" />
      <el-table-column min-width="140" prop="if_screen" label="是否飘屏">
        <template #default="scope">
          {{ filtersType(scope.row.if_screen) }}
        </template>
      </el-table-column>
      <el-table-column min-width="140" prop="if_notice" label="是否页面公告">
        <template #default="scope">
          {{ filtersType(scope.row.if_notice) }}
        </template>
      </el-table-column>
      <el-table-column min-width="140" prop="base_rate" label="基础概率(万分)" />
      <el-table-column min-width="140" prop="low_rate" label="低回概率" />
      <el-table-column min-width="140" prop="high_rate" label="高回概率" />
      <el-table-column min-width="140" prop="new_protect_rate" label="新人保护概率" />
      <el-table-column min-width="140" prop="day_rate_1" label="每日保护概率1" />
      <!-- <el-table-column min-width="140" prop="day_rate_2" label="每日保护概率2" /> -->
      <el-table-column width="200" fixed=right label="操作">
        <template #default="scope">
          <el-button v-rule="'equip_poolTwoList'" type="primary" @click="openTwoList(scope.row)">二级礼物池</el-button>
          <el-button type="primary" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <poolTwoList ref="poolTwoListRef" />
    <updateForm ref="updateFormRef" @update-list="getList" />
  </div>
</template>

<style lang='scss' scoped>

</style>
